package com.zzz.web.Servlet;

import com.zzz.web.DB.operationOnDataBase;
import com.zzz.web.Data.NewRssiList;
import com.zzz.web.Data.RSSI;
import com.zzz.web.Data.XYaxis;
import com.zzz.web.Data.validityRSSI;
import com.zzz.web.LocationAlgo.KalmanFilter;
import com.zzz.web.LocationAlgo.Update;
import com.zzz.web.LocationAlgo.WKNN;
import com.zzz.web.tools.tool;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.SQLException;
import java.util.ArrayList;

public class MyLocation extends HttpServlet {

    NewRssiList[] newRssiLists = new NewRssiList[30];

    private ArrayList<RSSI> rssiList = new ArrayList<RSSI>();

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String data = req.getParameter("data");
        RSSI rssi = tool.getRssi(data);
        //rssi是获取到的数据
        rssi.setNumber(12345);

        rssiList.add(rssi);

        if (rssiList.size() >= 10) {
            new Thread() {
                @Override
                public void run() {

                    RSSI validityRSSI = tool.avgRSSI(rssiList);

                    XYaxis xyaxis = WKNN.Match_WKNN(validityRSSI);

                    new operationOnDataBase().insertIntoXY(xyaxis);

                    Update update = Update.getInstance();
                    update.updataRSSI(new validityRSSI(xyaxis,validityRSSI));
                }
            }.start();
        }
    }
}

